package gant.ext

import org.codehaus.gant.GantBuilder
import org.junit.BeforeClass
import org.junit.Test
import org.slf4j.LoggerFactory

/**
 * Created by IntelliJ IDEA.
 * User: tbarker
 * Date: 4/27/12
 * Time: 2:00 PM
 */
class LoggingTest {

    @Test
    void "test basic logging"() {
        new GantActivator().setUpSlf4j()
        def out = new ByteArrayOutputStream()
        AntBuilderFactory.instance.builder.logger.outputPrintStream = new PrintStream(out)
        def log = LoggerFactory.getLogger("foo")
        log.info("hey from foo")
        assert out.toString().contains("hey from foo")
        assert out.toString().contains("info")

        log = LoggerFactory.getLogger(LoggingTest)
        log.warn("hey from bar")
        assert out.toString().contains("hey from bar")
        assert out.toString().contains("info")
    }

    @BeforeClass
    static void "setup builder factory"() {
        AntBuilderFactory.reset()
        AntBuilderFactory.createInstance(new GantBuilder())
    }
}
